local skill = fk.CreateSkill{
  name = "lvshi__qingguo",
  tags = {Skill.Switch, "Turn"},
}

Fk:loadTranslationTable{
  ["lvshi__qingguo"] = "倾国",
  [":lvshi__qingguo"] = "转换技，回合技，当其他角色①造成伤害时②回复体力时，你可取消之，并令其执行一次将置底改为交给你的“洛涌”。",
  [":lvshi__qingguo_yang"] = "转换技，回合技，当其他角色<font color=\"#0FFF50\">①造成伤害时</font>②回复体力时，你可取消之，并令其执行一次将置底改为交给你的“洛涌”。",
  [":lvshi__qingguo_yin"] = "转换技，回合技，当其他角色①造成伤害时<font color=\"#0FFF50\">②回复体力时</font>，你可取消之，并令其执行一次将置底改为交给你的“洛涌”。",
  ["#lvshi__qingguo-damage"] = "倾国：你可以防止 %src 对 %dest 造成的伤害，令其执行“洛涌”",
  ["#lvshi__qingguo-recover"] = "倾国：你可以防止 %src 回复体力，令其执行“洛涌”",
  ["#lvshi__qingguo-give"] = "倾国：将一张牌交给 %src",

  ["$lvshi__qingguo1"] = "画堂芳菲梦，琼酿玉衣怜。",
  ["$lvshi__qingguo2"] = "玉箸凝腮，姿貌绝伦。",
}

skill:addEffect(fk.DamageCaused, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skill.name) and target and target ~= player and player:usedSkillTimes(skill.name) == 0
    and player:getSwitchSkillState(skill.name, false) == fk.SwitchYang
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {
      skill_name = skill.name,
      prompt = "#lvshi__qingguo-damage:"..target.id..":"..data.to.id
    }) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "qingguo_damage-round")
    if not target:isNude() then
      local cards = room:askToCards(target, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = "lvshi__luoyong",
        cancelable = false,
        prompt = "#lvshi__qingguo-give:"..player.id
      })
      room:obtainCard(player, cards, true, fk.ReasonGive, target, skill.name)
    end
    if not target.dead then
      Fk.skills["lvshi__luoyong"]:onUse(room, {from = target, tos = {}, cards = {}})
    end
    data:preventDamage()
  end,
})

skill:addEffect(fk.PreHpRecover, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skill.name) and target ~= player and player:usedSkillTimes(skill.name) == 0
    and target:isWounded() and player:getSwitchSkillState(skill.name, false) == fk.SwitchYin
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {
      skill_name = skill.name,
      prompt = "#lvshi__qingguo-recover:"..target.id
    }) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "qingguo_recover-round")
    if not target:isNude() then
      local cards = room:askToCards(target, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = "lvshi__luoyong",
        cancelable = false,
        prompt = "#lvshi__qingguo-give:"..player.id
      })
      room:obtainCard(player, cards, true, fk.ReasonGive, target, skill.name)
    end
    if not target.dead then
      Fk.skills["lvshi__luoyong"]:onUse(room, {from = target, tos = {}, cards = {}})
    end
    data:preventRecover()
  end,
})

return skill